package com.sergiandreplace.kaboom.browser;

import java.io.File;
import java.util.ArrayList;

import com.sergiandreplace.kaboom.R;



public  class FileTypes
{
	private static ArrayList<FileType> types=new ArrayList<FileType>();
	private static FileTypes singletonFyleTypes;
	
	private static final int ORDER_PARENT=0;
	private static final int ORDER_FOLDER=1;
	private static final int ORDER_FILE=2;
	private FileTypes()
	{ 
		//types.add(new FileType(regExp, icon, iconForbidden, isDirectory, isComic));
		types.add(new FileType("Parent directory", ".*\\.\\.", ORDER_PARENT,R.drawable.folder_up, R.drawable.folder_forbid, true, false, true)); //one up
		
		types.add(new FileType("SD Card","/sdcard/*",ORDER_FOLDER, R.drawable.folder_sdcard, R.drawable.folder_forbid, true, false)); //sdcard directory
		types.add(new FileType("SD Card", "/mnt/sdcard/*",ORDER_FOLDER, R.drawable.folder_sdcard, R.drawable.folder_forbid, true, false)); //mnt/sdcard directory
		types.add(new FileType("SD Card","/sdcard[0-9]/*",ORDER_FOLDER, R.drawable.folder_sdcard, R.drawable.folder_forbid, true, false)); //sdcard directory
		types.add(new FileType("SD Card", "/mnt/sdcard[0-9]/*",ORDER_FOLDER, R.drawable.folder_sdcard, R.drawable.folder_forbid, true, false)); //mnt/sdcard directory
		types.add(new FileType("Directory", ".*",ORDER_FOLDER, R.drawable.folder, R.drawable.folder_forbid, true, false)); //normal directory
		
		//files
		types.add(new FileType("CBR comic. Not yet supported",".*.cbr",ORDER_FILE, R.drawable.file_rar, R.drawable.file_forbid, false, false)); //normal directory
		types.add(new FileType("CBZ comic", ".*cbz",ORDER_FILE, R.drawable.file_comic, R.drawable.file_forbid, false, true)); //normal directory
		types.add(new FileType("JPG Image",".*", ORDER_FILE,R.drawable.file_graphic, R.drawable.file_forbid, false, false)); //normal directory
		types.add(new FileType("File", ".*",ORDER_FILE, R.drawable.file_other, R.drawable.file_forbid, false, false)); //normal directory
	}
	
	public static FileType getFileType(String path, String filename)
	{
		if (singletonFyleTypes==null)
			singletonFyleTypes=new FileTypes();
		if (!path.matches(".*/")) path+="/";
		String fullName=path + filename;
		for (FileType type : types)
		{
			if (type.isDirectory()==(new File(fullName).isDirectory()) && fullName.matches(type.getRegExp()))
				return type;
		}
		return null;
		
	}
}
